package cn.iocoder.yudao.module.xhyy.controller.admin.notice;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.xhyy.controller.admin.notice.vo.NoticeXHPageReqVO;
import cn.iocoder.yudao.module.xhyy.controller.admin.notice.vo.NoticeXHRespVO;
import cn.iocoder.yudao.module.xhyy.controller.admin.notice.vo.NoticeXHSaveReqVO;
import cn.iocoder.yudao.module.xhyy.dal.dataobject.notice.NoticeXHDO;
import cn.iocoder.yudao.module.xhyy.service.notice.NoticeXHService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 通知")
@RestController
@RequestMapping("/xhyy/notice")
@Validated
public class NoticeXHController {

    @Resource
    private NoticeXHService noticeXHService;

    @PostMapping("/create")
    @Operation(summary = "创建通知")
    @PreAuthorize("@ss.hasPermission('xhyy:notice:create')")
    public CommonResult<Integer> createNoticePeiZhen(@Valid @RequestBody NoticeXHSaveReqVO createReqVO) {
        return success(noticeXHService.createNoticePeiZhen(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新通知")
    @PreAuthorize("@ss.hasPermission('xhyy:notice:update')")
    public CommonResult<Boolean> updateNoticePeiZhen(@Valid @RequestBody NoticeXHSaveReqVO updateReqVO) {
        noticeXHService.updateNoticePeiZhen(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除通知")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('xhyy:notice:delete')")
    public CommonResult<Boolean> deleteNoticePeiZhen(@RequestParam("id") Integer id) {
        noticeXHService.deleteNoticePeiZhen(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得通知")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('xhyy:notice:query')")
    public CommonResult<NoticeXHRespVO> getNoticePeiZhen(@RequestParam("id") Integer id) {
        NoticeXHDO noticePeiZhen = noticeXHService.getNoticePeiZhen(id);
        return success(BeanUtils.toBean(noticePeiZhen, NoticeXHRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得通知分页")
    @PreAuthorize("@ss.hasPermission('xhyy:notice:query')")
    public CommonResult<PageResult<NoticeXHRespVO>> getNoticePeiZhenPage(@Valid NoticeXHPageReqVO pageReqVO) {
        PageResult<NoticeXHDO> pageResult = noticeXHService.getNoticePeiZhenPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, NoticeXHRespVO.class));
    }


}